<?php
	include("../Includes/FusionCharts.php");
	include("../Includes/DBConn.php");
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml">
	<HEAD>
		<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
		<title>UPLB DV</title>
		
		<script language="Javascript" src="../js/FusionCharts.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.min.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.mousewheel-3.0.4.pack.js"></script>
		<script type="text/javascript" src="../fancybox/jquery.fancybox-1.3.4.pack.js"></script>
		<script type="text/javascript">

		$(document).ready(function() {
			$("a#example1").fancybox();

			$("a#example2").fancybox({
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'elastic'
			});

			$("a#example3").fancybox({
				'transitionIn'	: 'none',
				'transitionOut'	: 'none'	
			});

			$("a#example4").fancybox({
				'opacity'		: true,
				'overlayShow'	: false,
				'transitionIn'	: 'elastic',
				'transitionOut'	: 'none'
			});

			$("a#example5").fancybox();

			$("a#example6").fancybox({
				'titlePosition'		: 'outside',
				'overlayColor'		: '#000',
				'overlayOpacity'	: 0.9
			});

			$("a#example7").fancybox({
				'titlePosition'	: 'inside'
			});

			$("a#example8").fancybox({
				'titlePosition'	: 'over'
			});

			$("a[rel=example_group]").fancybox({
				'transitionIn'		: 'none',
				'transitionOut'		: 'none',
				'titlePosition' 	: 'over',
				'titleFormat'		: function(title, currentArray, currentIndex, currentOpts) {
				return '<span id="fancybox-title-over">Image ' + (currentIndex + 1) + ' / ' + currentArray.length + (title.length ? ' &nbsp; ' + title : '') + '</span>';
			}
		});

			$("#various1").fancybox({
					'titlePosition'		: 'inside',
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

			$("#various2").fancybox();

			$("#various3").fancybox({
					'width'				: '75%',
					'height'			: '75%',
					'autoScale'			: false,
					'transitionIn'		: 'elastic',
					'transitionOut'		: 'elastic',
					'type'				: 'iframe'
			});

			$("#various4").fancybox({
					'padding'			: 0,
					'autoScale'			: false,
					'transitionIn'		: 'none',
					'transitionOut'		: 'none'
			});

		});

	</script>

		<link rel="stylesheet" href="../fancybox/jquery.fancybox-1.3.4.css" type="text/css" media="screen" />

	</HEAD>

	<BODY bgcolor="white">
	<CENTER>
			<?php
				$subject = $_GET['subject'];
				//echo $subject;
				if($subject=="default"){
					$snfirst = 2007;
					$snlast = 36018;
					$semester = 1;
					$kindofgraph = 'FCF_LINE';
				}
				else{
					$snfirst = $_POST['sn_first'];
					$snlast = $_POST['sn_last'];
					$semester = 1;
					$kindofgraph = 'FCF_LINE';
					
				}
				
					$snnumber = $snfirst.$snlast;
					$studentnumber = $snfirst."-".$snlast;
					
					// Connect to the DB
				$link = connectToDB();

				//$strXML will be used to store the entire XML document generated
				//Generate the graph element
				//fetch the name of the specified student number
				$strQuery0 = "select * from tempStudents where studentNumber='$snnumber'";
				$result0 = mysql_query($strQuery0) or die(mysql_error());
				$ors = mysql_fetch_array($result0);
				$fullname = $ors['firstName']." ".$ors['lastName'];
				
				
				
				
				$strQuery1 = "select mayts from tempStudents where studentNumber='$snnumber'";
				$result1 = mysql_query($strQuery1) or die(mysql_error());
				$ors1 = mysql_fetch_array($result1);
				$maxallowed = $ors1['mayts'];
				
				
					$ay = $snfirst;
					$strXML = "<graph caption='Units Earned' subCaption='$fullname' showBorder='1' xAxisName='Semesters' yAxisName='Units Earned' showNames='1'  formatNumberScale='0' decimalPrecision='0' yaxisminvalue='0' yaxismaxvalue='144' numdivlines='5'> ";
					$tu = 0;
				
					while($ay <= $snfirst + $maxallowed){
					// Fetch all factory records
						
							$strQuerytotal = "select SUM(units) as totalunits from tempSubjects where studentNumber='$snnumber' and academicYear='$ay' and semester='$semester' and grade<='3.00'";
							$resulttotal = mysql_query($strQuerytotal) or die(mysql_error());
							$orstotal = mysql_fetch_array($resulttotal);
							
							if($ay >= $snfirst+(($maxallowed/3)*2)){
								
									if($semester == 1){
										$semname ="1st";
									}
									else if($semester == 2){
										$semname = "2nd";
									}
									else if($semester == 3){
										$semname = "3rd";
									}
								if($orstotal['totalunits']>0){
									
									$tu =  $tu + $orstotal['totalunits'];
									
									$ayt = $ay."".($ay+1);
									//$strXML .= "<set name='" . $semname . " ". $ayt. "' value='" . $tu . "' />";
								}//end of outside if
								
								else{
									$ayt = $ay."".($ay+1);
									//$strXML .= "<set name='" . $semname . " ". $ayt. "' />";
								}
							}
																						
							if($orstotal['totalunits']>0){
								
								$tu =  $tu + $orstotal['totalunits'];
								if($semester == 1){
									$semname ="1st";
								}
								else if($semester == 2){
									$semname = "2nd";
								}
								else if($semester == 3){
									$semname = "3rd";
								}
								$ayt = $ay."".($ay+1);
								$strXML .= "<set name='" . $semname . " ". $ayt. "' value='" . $tu . "' />";
							}//end of outside if
														
							
							
							if($semester == 3){
								$ay=$ay + 1;
								$semester=1;
							}
							else{
								$semester++;
							}
						
					}//end of while
					
					//close the link
					mysql_close($link);

					//Finally, close <graph> element
					$strXML .= "</graph>";
					$graph = $kindofgraph.".swf";
					//Create the chart - Pie 3D Chart with data from $strXML
					echo renderChart("../FusionCharts/$graph", "", $strXML, "FactorySum", 850, 430);
				
			?>
	</CENTER>
	</BODY>
</HTML>